#pragma once

#include "CommonNamespace.h"
#include "OptPoint.h"

BEGIN_OPT_NAMESPACE

struct Func2Abstract
{
	Func2Abstract()
		: _calculateCount(0)
	{}

	inline void reset() { _calculateCount = 0; }
	inline unsigned int count() { return _calculateCount; }

	virtual std::string toStdString() = 0;
	virtual double F(const OptPoint& v) const = 0;
	virtual double operator () (const OptPoint&) const = 0;

protected:
	mutable unsigned int _calculateCount;
};

struct RozenbrokFunc : Func2Abstract
{
	virtual std::string toStdString()
	{
		return std::string("100 * (y - x^2)^2 + (1 - x)^2");
	}

	virtual double F(const OptPoint& v) const
	{
		++_calculateCount;
		return 100.0 * math::sqr(v.y() - math::sqr(v.x())) + math::sqr(1.0 - v.x());
	}

	virtual double operator () (const OptPoint& v) const
	{
		return F(v);
	}
};

END_OPT_NAMESPACE